home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Graphic Gems I, II & III (C_C++) / Graphics Gems C Code.sea / GemsII / dither / dither.3 next >
Text File  |  1992-06-16  |  4KB  |  158 lines

  1. .\" Copyright (c) 1986, 1987, University of Utah
  2. .TH DITHER 3 2/2/87 3
  3. .UC 4 
  4. .SH NAME
  5. .HP
  6. dithermap, bwdithermap, make_square, dithergb, ditherbw \- functions for dithering color or black and white images.
  7. .SH SYNOPSIS
  8. .na
  9. .sp
  10. .B
  11. dithermap( levels, gamma, rgbmap, divN, modN, magic )
  12. .br
  13. .B
  14. int levels;
  15. .br
  16. .B
  17. double gamma;
  18. .br
  19. .B
  20. int rgbmap[][3], divN[256], modN[256], magic[16][16];
  21. .sp
  22. .B
  23. bwdithermap( levels, gamma, bwmap, divN, modN, magic )
  24. .br
  25. .B
  26. int levels;
  27. .br
  28. .B
  29. double gamma;
  30. .br
  31. .B
  32. int bwmap[], int divN[256], modN[256], magic[16][16];
  33. .sp
  34. .B
  35. make_square( N, divN, modN, magic )
  36. .br
  37. .B
  38. double N;
  39. .br
  40. .B
  41. int divN[256], modN[256], magic[16][16];
  42. .sp
  43. .B
  44. dithergb( x, y, r, g, b, levels, divN, modN, magic )
  45. .br
  46. .B
  47. int x, y, r, g, b, levels;
  48. .br
  49. .B
  50. int divN[256], modN[256], magic[16][16];
  51. .sp
  52. .B
  53. ditherbw( x, y, val, divN, modN, magic )
  54. .br
  55. .B
  56. int x, y, val, divN[256], modN[256], magic[16][16];
  57. .ad b
  58. .SH DESCRIPTION
  59. These functions provide a common set of routines for dithering a full
  60. color or gray scale image into a lower resolution color map.  
  61.  
  62. .I Dithermap
  63. computes a color map and some auxiliary parameters for dithering a
  64. full color (24 bit) image to fewer bits.  The argument
  65. .I levels
  66. tells how many different intensity levels per primary color should be
  67. computed.  To get maximum use of a 256 entry color map, use
  68. .IR levels =6.  
  69. The computed map uses \fIlevels^3\fP entries.
  70. The
  71. .I gamma 
  72. argument provides for gamma compensation of the generated color map
  73. (that is, the values in the map will be adjusted to give a linear
  74. intensity variation on a display with the given gamma).
  75. The computed color map will be returned in the array
  76. .IR rgbmap .
  77. .I divN
  78. and
  79. .I modN
  80. are auxiliary arrays for computing the dithering pattern (see below),
  81. and
  82. .I magic
  83. is the magic square dither pattern.
  84. .PP
  85. To compute a color map for dithering a black and white image to fewer
  86. intensity levels, use
  87. .IR bwdithermap .
  88. The arguments are as for
  89. .IR dithermap ,
  90. but only a single channel color map is computed.  The value of
  91. \fIlevels\fP can be larger than for \fIdithermap\fP, as
  92. the computed map only has \fIlevels\fP entries.
  93. .PP
  94. To just build the magic square and other parameters, use
  95. .IR make_square .
  96. The argument
  97. .I N
  98. should be equal to 255.0 divided by the desired number of intensity
  99. levels less one (i.e., \fIN = 255.0 / (levels - 1)\fP).  The other
  100. arguments are filled in as above.
  101. .PP
  102. The color map index for a dithered full color pixel is computed by
  103. .IR dithergb .
  104. Since the pattern depends on the screen location, the first two
  105. arguments
  106. .IR x 
  107. and
  108. .IR y ,
  109. specify that location.  The true color of the pixel at that location
  110. is given by the triple
  111. .IR r ,
  112. .IR g ,
  113. and
  114. .IR b .
  115. The number of intensity
  116. .I levels
  117. and the dithering parameter matrices computed by
  118. .I dithermap
  119. are also passed to 
  120. .IR dithergb .
  121. .PP
  122. The color map index for a dithered gray scale pixel is computed by
  123. .IR ditherbw .
  124. Again, the screen position is specified, and the intensity value of
  125. the pixel is supplied in
  126. .IR val .
  127. The dithering parameters must also be supplied.
  128. .PP
  129. Alternatively, the dithering may be done in line instead of incurring
  130. the extra overhead of a function call, which can be significant when
  131. repeated a million times.  The computation is as follows:
  132. .nf
  133. .ta .5i 1.0i 1.5i
  134.         row = y % 16;
  135.         col = x % 16;
  136.     #define DMAP(v,col,row) (divN[v] + (modN[v]>magic[col][row] ? 1 : 0))
  137.         pix = DMAP(r,col,row) + DMAP(g,col,row)*levels +
  138.             DMAP(b,col,row)*levels*levels;
  139. .fi
  140. For a gray scale image, it is a little simpler:
  141. .nf
  142. .ta .5i 1.0i 1.5i
  143.         pix = DMAP(val,row,col);
  144. .fi
  145. And on a single bit display (assuming a 1 means white):
  146. .nf
  147. .ta .5i 1.0i
  148.         pix = divN[val] > magic[col][row] ? 1 : 0
  149. .fi
  150. .SH SEE ALSO
  151. .IR rgb_to_bw (3),
  152. .IR librle (3),
  153. .IR RLE (5).
  154. .SH AUTHOR
  155. Spencer W. Thomas
  156. .br
  157. University of Utah
  158.